# domtree.py
# This is a simple example for idlelib.TreeWidget

# Written by Seo Sanghyeon
# Put into the public domain

from Tkinter import Tk, Canvas
from xml.dom.minidom import parseString
import dicttoxml,json
from idlelib.TreeWidget import TreeItem, TreeNode

class DomTreeItem(TreeItem):
    def __init__(self, node):
        self.node = node
    def GetText(self):
        node = self.node
        if node.nodeType == node.ELEMENT_NODE:
            return node.nodeName
        elif node.nodeType == node.TEXT_NODE:
            return node.nodeValue
    def IsExpandable(self):
        node = self.node
        return node.hasChildNodes()
    def GetSubList(self):
        parent = self.node
        children = parent.childNodes
        prelist = [DomTreeItem(node) for node in children]
        itemlist = [item for item in prelist if item.GetText().strip()]
        return itemlist

data ="""
[
{"index":1,"itemType":"cascade","tearoff":0,"value":{"label":"File","menu":"menuItem"},"item":[]},
{"index":2,"itemType":"cascade","tearoff":0,"value":{"label":"Edit","menu":"menuItem"}},
{"index":3,"itemType":"cascade","tearoff":0,"value":{"label":"Find","menu":"menuItem"}},
{"index":4,"itemType":"cascade","tearoff":0,"value":{"label":"About","menu":"menuItem"}},
{"index":5,"itemType":"cascade","tearoff":0,"value":{"label":"Open","command":""}},
{"index":6,"itemType":"cascade","tearoff":0,"value":{"label":"History","command":""}},
{"index":7,"itemType":"cascade","tearoff":0,"value":{"label":"Save","command":""}},
{"index":8,"itemType":"cascade","tearoff":0,"value":{"label":"Exit","command":""}},
{"index":9,"itemType":"cascade","tearoff":0,"value":{"label":"Copy","command":""}},
{"index":10,"itemType":"cascade","tearoff":0,"value":{"label":"Paste","command":""}},
{"index":11,"itemType":"cascade","tearoff":0,"value":{"label":"Encode","command":""},"father":1}

]
"""


root = Tk()
canvas = Canvas(root)
canvas.config(bg='white')
canvas.pack()
jsonObj=json.loads(data)
print jsonObj
xmldata =dicttoxml.dicttoxml(jsonObj);
print xmldata
dom = parseString(xmldata)
item = DomTreeItem(dom.documentElement)
node = TreeNode(canvas, None, item)
node.update()
node.expand()
root.mainloop()
